<?php
/**
 * unsubscribe header_php.php 
 *
 * @package page
 * @copyright Copyright 2003-2009 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: header_php.php 14141 2009-08-10 19:34:47Z wilt $
 */

// This should be first line of the script:
$zco_notifier->notify('NOTIFY_HEADER_START_UNSUBSCRIBE');

require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

//present the option to unsubscribe, with a confirm button/link


$breadcrumb->add(NAVBAR_TITLE, zen_href_link(FILENAME_TRACK_ORDER, '', 'NONSSL'));


// if they clicked on the "confirm unsubscribe" then process it:
if (isset($_POST['action']) && ($_POST['action'] == 'find')) {
  if(zen_db_prepare_input($_POST['btnSubmit1'])!=''){	
   if($_POST['txtEmail1']!="" and  $_POST['order_id1']!=''){	
	  $txtEmail1 = zen_db_prepare_input($_POST['txtEmail1']);	
	  $order_id1 = zen_db_prepare_input($_POST['order_id1']);	
      $track_order_sql =   "select o.orders_id, o.customers_id,o.delivery_name,o.delivery_country,o.billing_name,o.billing_country, o.customers_name, o.date_purchased, o.currency_value,o.track_order_info, s.orders_status_name, ot.text as order_total
                            from (" . TABLE_ORDERS_STATUS . " s, " . TABLE_ORDERS . " o )
                            left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id and ot.class = 'ot_total') " . "
                            where o.customers_email_address = :emailAddress
                                  and o.orders_id=:order_id
                                  and o.orders_status = s.orders_status_id 
                                  and s.language_id = '" . (int)$_SESSION['languages_id'] . "' order by orders_id DESC";
      $track_order_sql = $db->bindVars($track_order_sql, ':emailAddress', $txtEmail1, 'string');
      $track_order_sql = $db->bindVars($track_order_sql, ':order_id', $order_id1, 'integer');
  }else{
  	  $warning_string='You MUST enter both Email and Order_id!';
  }
}
  if(zen_db_prepare_input($_POST['btnSubmit2'])!=''){	
   if($_POST['txtName2']!="" and  $_POST['order_id2']!=''){	
	  $txtName2 = zen_db_prepare_input($_POST['txtName2']);	
	  $order_id2 = zen_db_prepare_input($_POST['order_id2']);
      $track_order_sql =   "select o.orders_id, o.customers_id,o.delivery_name,o.delivery_country,o.billing_name,o.billing_country, o.customers_name, o.date_purchased, o.currency_value,o.track_order_info, s.orders_status_name, ot.text as order_total
                            from (" . TABLE_ORDERS_STATUS . " s, " . TABLE_ORDERS . " o )
                            left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id and ot.class = 'ot_total') " . "
                            where o.customers_name = :customers_name
                                  and o.orders_id=:order_id
                                  and o.orders_status = s.orders_status_id 
                                  and s.language_id = '" . (int)$_SESSION['languages_id'] . "' order by orders_id DESC";
      $track_order_sql = $db->bindVars($track_order_sql, ':customers_name', $txtName2, 'string');
      $track_order_sql = $db->bindVars($track_order_sql, ':order_id', $order_id2, 'integer');	
  }else{
  	  $warning_string='You MUST enter both Customer Name and Order_id!';
  }
}    
 if($track_order_sql){
	  $track_order = $db->Execute($track_order_sql);
	
	  // If we found the customer's email address, and they currently subscribe
	  if ($track_order->RecordCount() >0) {
  if (zen_not_null($track_order->fields['delivery_name'])) {
    $order_name = $track_order->fields['delivery_name'];
    $order_country = $track_order->fields['delivery_country'];
  } else {
    $order_name = $track_order->fields['billing_name'];
    $order_country = $track_order->fields['billing_country'];
  }
	  	
	  	
  $ordersArray = array('orders_id'=>$track_order->fields['orders_id'],
  'date_purchased'=>$track_order->fields['date_purchased'],
  'order_name'=>$order_name,
  'order_country'=>$order_country,
  'orders_status_name'=>$track_order->fields['orders_status_name'],
  'order_total'=>$track_order->fields['order_total'],
   'track_order_info'=>$track_order->fields['track_order_info'],

  );
  
	  } else {
	    // If not found, we want to display an error message (This should never occur, unless they try to unsubscribe twice)
	    $warning_string='There is no record in your search.';
	  }
 }	

}


// This should be last line of the script:
$zco_notifier->notify('NOTIFY_HEADER_END_UNSUBSCRIBE');
?>